'use strict';

// Define the `phonecatApp` module
var carousel = angular.module('carousel', [
    'ngAnimate',
    'ngRoute',
    'core.phone',
    'ngResource'

]);

carousel.directive('items', function ($timeout) {
    return {
        restrict: "EA",
        replace: true,
        templateUrl: 'carousel/submenu.html',
        transclude: true,
        link: function (scope, element, attr) {
            if (scope.$last === true) {
                $timeout(function () {
                    scope.$emit('ngRepeatFinished');
                });
            }
        }
    }
});
carousel.component('carousel', {
    templateUrl: 'carousel/carousel.template.html',
    controller: ['$routeParams', 'Phone','$scope',
        function CarouselController($routeParams,Phone,$scope) {
            this.phones = Phone.query();
            $scope.$on('ngRepeatFinished', function (ngRepeatFinishedEvent) {
                var swiper = new Swiper('.swiper-container', {
                    pagination: '.swiper-pagination',
                    nextButton: '.swiper-button-next',
                    prevButton: '.swiper-button-prev',
                    paginationClickable: true,
                    mousewheelControl: true,
                    centeredSlides: true,
                    autoplay: 2000,
                    effect: "coverflow",
//        fade: {
//            crossFade: true
//        },
                    autoplayDisableOnInteraction: false,
                    paginationBulletRender: function (swiper, index, className) {
                        return '<span class="' + className + '">' + (index + 1) + '</span>';
                    }
                });
            });
        }

    ]
});

